package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.EmoticonType;
import com.ruoyi.business.domain.bo.EmoticonTypeBo;
import com.ruoyi.business.domain.vo.EmoticonTypeVo;
import com.ruoyi.business.mapper.EmoticonTypeMapper;
import com.ruoyi.business.service.IEmoticonTypeService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 最爱喝兽奶
 * @create 2022/7/24
 **/
@Service
public class EmoticonTypeServiceImpl extends ServiceImpl<EmoticonTypeMapper, EmoticonType> implements IEmoticonTypeService {
    @Override
    public List<EmoticonTypeVo> list(EmoticonTypeBo bo) {
        List<EmoticonType> list = baseMapper.selectList(buildQueryWrapper(bo));
        List<EmoticonTypeVo> ans = list.stream().map(item -> {
            EmoticonTypeVo vo = new EmoticonTypeVo();
            BeanUtils.copyProperties(item, vo);
            return vo;
        }).collect(Collectors.toList());
        return ans;
    }

    private LambdaQueryWrapper<EmoticonType> buildQueryWrapper(EmoticonTypeBo bo) {
        LambdaQueryWrapper<EmoticonType> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(bo.getTypeName()), EmoticonType::getTypeName, bo.getTypeName());
        return lqw;
    }
}
